<template>
  <el-checkbox-group v-model="sendType" @change="handleChange">
    <el-checkbox label="SMS" @change="handleItemChange">{{ '通过短信发送'}}</el-checkbox>
    <el-checkbox label="EMAIL" @change="handleItemChange">{{ $t('loc.sendViaEmail') }}</el-checkbox>
  </el-checkbox-group>
</template>

<script>
export default {
  name: "SendSetting",
  props: [
    'modelValue'
  ],
  data() {
    return {
      sendTypes: ['SMS', 'EMAIL'],
      sendType: ['SMS', 'EMAIL'],
      lastChanged: null,
    }
  },
  created() {
    this.handleChange(this.sendTypes)
  },
  methods: {
    handleItemChange(value, event) {
      this.lastChanged = {value, event};
    },
    handleChange(values) {
      if (values.length) {
        console.log("sdsd", values)
        this.$emit('update:modelValue', this.calculateValue(values));
        return;
      }
      let {event} = this.lastChanged;
      this.sendType.push(event.target._value);
      this.$emit('update:modelValue', this.calculateValue(this.sendType));
    },
    calculateValue(sendType = []) {
      console.log(sendType)
      return this.sendTypes.every(item => sendType.includes(item)) ? 'Recommend' : sendType.join(",");
    },
    reset() {
      this.sendType = [...this.sendTypes];
    }
  }
}
</script>

<style scoped>

</style>